package com.ease.platform.access.service.impl;

import java.util.List;

import com.ease.common.util.Assertion;
import com.ease.dao.DataAccessObjectConst;
import com.ease.dao.JdbcTemplateDataAccessObject;
import com.ease.dao.statement.factory.NamedStatementFactory;
import com.ease.model.Model;
import com.ease.platform.access.callback.GroupingAccessCallback;
import com.ease.platform.access.service.AbstractJdbcTemplateAccessService;
import com.ease.platform.authorization.service.impl.AbstractAuthorizationServiceImpl;

/**
 * 
 * @author nathanleewei
 * 
 */
public abstract class AbstractJdbcTemplateAccessServiceImpl extends AbstractAuthorizationServiceImpl implements AbstractJdbcTemplateAccessService {

	protected int numberOfExpressionsUsingInClause = DataAccessObjectConst.MAXIMUM_NUMBER_OF_EXPRESSIONS_USING_IN_CLAUSE;

	protected boolean findByIdsUsingInClause = true;

	protected JdbcTemplateDataAccessObject jdbcTemplateDataAccessObject;

	protected NamedStatementFactory namedStatementFactory;

	protected String owner;

	protected String getNamedStatement(String statementName, Object parameter) {
		String namedStatement = namedStatementFactory.getNamedStatement(statementName, parameter);
		Assertion.notEmpty(namedStatement, "namedStatement not found, statementName=" + statementName);
		return namedStatement;
	}

	/**
	 * 一般用于当in条件参数个数>1000个时,进行分组查询
	 * 
	 * @param <T>
	 * @param parameters
	 * @param
	 * @param groupingAccessCallback
	 * @return
	 */
	protected <T extends Model> List<T> groupingAccess(long[] parameters, GroupingAccessCallback<T> groupingAccessCallback) {
		return groupingAccessCallback.makeGroup(parameters, this.getNumberOfExpressionsUsingInClause());
	}

	/**
	 * @return the numberOfExpressionsUsingInClause
	 */
	public int getNumberOfExpressionsUsingInClause() {
		return numberOfExpressionsUsingInClause;
	}

	/**
	 * @param numberOfExpressionsUsingInClause
	 *            the numberOfExpressionsUsingInClause to set
	 */
	public void setNumberOfExpressionsUsingInClause(int numberOfExpressionsUsingInClause) {
		this.numberOfExpressionsUsingInClause = numberOfExpressionsUsingInClause;
	}

	/**
	 * @return the findByIdsUsingInClause
	 */
	public boolean isFindByIdsUsingInClause() {
		return findByIdsUsingInClause;
	}

	/**
	 * @param findByIdsUsingInClause
	 *            the findByIdsUsingInClause to set
	 */
	public void setFindByIdsUsingInClause(boolean findByIdsUsingInClause) {
		this.findByIdsUsingInClause = findByIdsUsingInClause;
	}

	/**
	 * @return the jdbcTemplateDataAccessObject
	 */
	public JdbcTemplateDataAccessObject getJdbcTemplateDataAccessObject() {
		return jdbcTemplateDataAccessObject;
	}

	/**
	 * @param jdbcTemplateDataAccessObject
	 *            the jdbcTemplateDataAccessObject to set
	 */
	public void setJdbcTemplateDataAccessObject(JdbcTemplateDataAccessObject jdbcTemplateDataAccessObject) {
		this.jdbcTemplateDataAccessObject = jdbcTemplateDataAccessObject;
	}

	/**
	 * @return the owner
	 */
	public String getOwner() {
		return owner;
	}

	/**
	 * @param owner
	 *            the owner to set
	 */
	public void setOwner(String owner) {
		this.owner = owner;
	}

	/**
	 * @return the namedStatementFactory
	 */
	public NamedStatementFactory getNamedStatementFactory() {
		return namedStatementFactory;
	}

	/**
	 * @param namedStatementFactory
	 *            the namedStatementFactory to set
	 */
	public void setNamedStatementFactory(NamedStatementFactory namedStatementFactory) {
		this.namedStatementFactory = namedStatementFactory;
	}

}
